package com.yanghui.lingyue.functions.defaultFunction

import com.icedata.sika.bridge.SikaEvent
import com.icedata.sika.bridge.SikaGroupEvent
import com.icedata.sika.core.CommandProcessor
import com.icedata.sika.core.Sika
import com.icedata.sika.util.Logger
import com.yanghui.lingyue.bot.Bot
import com.yanghui.lingyue.data.Command
import java.util.*

object AdministratorHandler {

    fun parse(event: SikaEvent, sika: Sika): LinkedList<Command> {
        val command = LinkedList<Command>()
        val user = Bot.userList[event.sender.id]
        user ?: return command
        if (!user.isAdministrator)
            return command
        if (!event.message.contentToString().startsWith("LingYue "))
            return command
        command.add(Command(event, "Admin", ""))
        return command
    }

    fun filter(command: Command): Boolean {
        return command.instruction == "Admin"
    }

    fun execute(command: Command, sika: Sika): CommandProcessor.Result {
        val instruction = command.event.message.contentToString().split(" ")
        when (instruction[1]) {
            "-close" -> Bot.groupList[(command.event as SikaGroupEvent).sendGroup.id]?.groupCache?.set(
                "OnActive",
                false
            )
            "-reload" -> {
                Logger.logDebug("Admin", "Reload")
                Bot.boot()
            }
        }
        return CommandProcessor.Result.ADOPT
    }

}